<?php

namespace app\models;

use Yii;
use yii\db\Query;

class Payinfo
{
    public function quotapay($post)
    {
        $res=[
            'cid'=>$post['cid'],
            'order_id'=>$post['order_id'],
            'type'=>$post['type'],
            'limit'=>$post['limit'],
            'created_at'=>time()
        ];
        $transaction = Yii::$app->db->beginTransaction();
        try {
            //增加使用额度
            $update = Yii::$app->db->createCommand('UPDATE bf_customer SET use_limit = use_limit+' . $post['limit'] . ' WHERE yid=' . $post['yid'])->execute();
            //添加额度使用记录
            $insert = Yii::$app->db->createCommand()->insert('bf_quotainfo', $res)->execute();
            $transaction->commit();
            return ['code' => 200, 'message' => 'OK', 'data' => ''];
        } catch (\Exception $e) {
            $transaction->rollBack();
            return ['code' => 401, 'message' => '修改失败', 'data' => ''];
        }
    }

    public function Repaypay($post)
    {
        //修改养护账期代付状态，代付时间
        //添加保付（资方）代付记录，修改保付资方额度，添加额度流水
        //添加保付（用户）待还记录
        $update = Yii::$app->db2->createCommand('UPDATE yt_accounting_period SET df_status =1,df_time='.time().' WHERE id='. $post['pid'])->execute();
        $sql="select a.account_code,a. From yt_trade_store a LEFT JOIN yt_user b ON b.cid = a.id LEFT JOIN yt_trade_infor c ON c.id =a.infor_id where a.id =" . $post['id'];
        $res=[
            'account_code'=>$post['account_code'],
            'investor_id'=>$post['id'],
            'tenend'=>$post['']



        ];

        if($update==1){

        }





    }

}
